Skip to content

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Apr 26, 2025

Commits should be reviewed in order.

@Girgias Girgias changed the title Random refacto ext/random: Various minor refactorings Apr 26, 2025
@Girgias Girgias marked this pull request as ready for review August 3, 2025 18:35
size_t len = hexstr->len >> 1;
unsigned char *str = (unsigned char *) hexstr->val, c, l, d;
const unsigned char *str = (unsigned char *) hexstr->val;
unsigned char c, l, d;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could also be pulled into the for(). In fact php_hex2bin (which is referenced in the comment above this function) already does. It makes sense to keep the two functions aligned.

}

non_64:
non_64:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop this one, it's intentional.

Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the hex2bin changes. Perhaps they should be done in a separate PR, since they are fixing an actual bug?

const unsigned char *str = (unsigned char *) ZSTR_VAL(hexstr);
unsigned char *ptr = (unsigned char *) dest;
int is_letter, i = 0;
uint32_t i = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a uint32_t used as an offset. Please:

Suggested change
uint32_t i = 0;
size_t i = 0;

Alternatively pointer arithmetic could be used on str.

size_t len = hexstr->len >> 1;
unsigned char *str = (unsigned char *) hexstr->val, c, l, d;
const unsigned char *str = (unsigned char *) ZSTR_VAL(hexstr);
unsigned char *ptr = (unsigned char *) dest;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned char *ptr = (unsigned char *) dest;
unsigned char *ptr = dest;

Unnecessary cast from void*.

size_t target_length = oldlen >> 1;
zend_string *str = zend_string_alloc(target_length, 0);
unsigned char *ret = (unsigned char *)ZSTR_VAL(str);
size_t i, j;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact here it was correct 😒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants